package com.example.demo.TestAOP;


import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.*;
import org.springframework.stereotype.Component;

@Component
@Aspect    //代表是一个切面类
public class TestAop {

@Pointcut("execution(* com.example.demo.Controller.TestController.* (..))")
   public void struct(){
}

@Before("struct()")
    public void fun(){
    System.out.println("你好哈哈哈哈");
    System.out.println("这是在目标方法前执行的");
}

@After("struct()")
    public void fun1(){
    System.out.println("这是在目标方法后执行的");
}

@AfterReturning("struct()")

    public void fun3(){
    System.out.println("目标方法后执行-出现异常不会被执行");
}

@AfterThrowing("struct()")

    public void fun4(){
    System.out.println("目标方法后执行-且出现异常才会被执行");
}

@Around("struct()")

    public void fun5(ProceedingJoinPoint joinPoint) throws Throwable {
    System.out.println("环绕通知前");
    joinPoint.proceed();
    System.out.println("环绕通知后");
}

}
